package com.bj58.mis.apm.server.logreceiver.config;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/**
 * @author: zhangfx
 * @create: 2018-06-07 15:28
 **/
@Component
@ConfigurationProperties(prefix = "apm.log")
public class LogReceiversConfig implements InitializingBean {
    private Logger logger = LoggerFactory.getLogger(this.getClass());

    private Map<String, Map<String ,String>> receivers = new HashMap<>();


    public Map<String, Map<String, String>> getReceivers() {
        return receivers;
    }

    public void setReceivers(Map<String, Map<String, String>> receivers) {
        this.receivers = receivers;
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        StringBuilder logInfo = new StringBuilder();
        logInfo.append("\n=========LogReceiverConfig========\n");
        for(String type : receivers.keySet()){
            logInfo.append("日志类型：").append(type).append(", ")
                    .append("日志Model: ").append(receivers.get(type).get("model")).append(", ")
                    .append("日志接收器: ").append(receivers.get(type).get("service")).append("\n");
        }
        logger.info(logInfo.toString());
    }
}
